<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>chat</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
    <div id="app">
        <button @click="conn">连接</button>
        <button @click="dis">关闭</button>
    </div>
    

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                ws: null,
                url: "ws://192.168.1.125:8080/ws?token=白峪&room=100",
            },
            created() {
              console.log('初始化成功')  
            },
            methods: {
                conn: function() {
                    console.log('建立连接')  
                    this.ws = new WebSocket(this.url)
                    this.ws.onopen = this.open
                    this.ws.onmessage = this.message
                    this.ws.onclose = this.close
                },
                open: function(e) {
                    this.ws.send('连接成功。。。。')
                },
                message: function(e) {
                    console.log(e)
                },
                close: function() {
                    console.log('连接断开')
                },
                dis: function() {
                    this.ws.close(1000, "aaa")
                },
                details: function() {
                    return  this.site + " - 学的不仅是技术，更是梦想！";
                }
            }
        })
    </script>
</body>
</html>